import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';

class MyPageController extends GetxController {

  final CommonPageController commonPageController = Get.find();

  /// 控制器
  ScrollController scrollController = ScrollController();
  double initBgHeight = 196.h;
  var bgHeight = 196.h.obs;
  var titleBarOpacity = 0.0.obs;
  var isOpen = false.obs;
  
  @override
  void onReady() {
    scrollController.addListener(() {
      if (scrollController.offset < 0) {
        titleBarOpacity.value = 0;
        bgHeight.value = initBgHeight;
        return;
      }
      if (scrollController.offset <= 0) {
        titleBarOpacity.value = 0;
      } else {
        if (scrollController.offset > 150.h + ScreenUtil().statusBarHeight) {
          titleBarOpacity.value = 1;
        } else {
          titleBarOpacity.value = (1 / (150.h + ScreenUtil().statusBarHeight)) * scrollController.offset;
        }
      }
      if (scrollController.offset < initBgHeight) {
        bgHeight.value = 196.h - scrollController.offset;
      } else {
        bgHeight.value = 0;
      }
    });
    super.onReady();
  }

}